﻿using System;
using System.ComponentModel;
using System.Runtime.InteropServices;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using Microsoft.SharePoint;
using Microsoft.SharePoint.WebControls;
using eGov.SharePoint.MyPeeps.WebControls;


namespace eGov.SharePoint.MyPeeps.WebParts
{

    [ToolboxItemAttribute(false)]
    public class ConsolidatedUpdatesWebPart : ActivityUpdatesWebPart
    {
        // Visual Studio might automatically update this path when you change the Visual Web Part project item.
        private const string _ascxPath = @"~/_CONTROLTEMPLATES/eGov/ConsolidatedUpdatesUserControl.ascx";

        private ConsolidatedUpdatesUserControl userControl;

        public ConsolidatedUpdatesWebPart()
        { }

        protected override void CreateChildControls()
        {
            if (!_error)
            {
                try
                {
                    base.CreateChildControls();
                    userControl = this.Page.LoadControl(_ascxPath) as ConsolidatedUpdatesUserControl;
                    if (userControl != null)
                    {
                        userControl.InitialFeedsCount = this.InitialFeedsCount;
                        userControl.ViewMoreCount = this.ViewMoreCount;
                        userControl.ViewMore = this.ViewMore;
                    }
                    Controls.Add(userControl);
                }
                catch (Exception ex)
                {
                    HandleException(ex);
                }
            }
        }

        protected override void OnEditModeChanged(EventArgs e)
        {
            /// Apply changes
            if (userControl != null)
            {
                userControl.InitialFeedsCount = this.InitialFeedsCount;
                userControl.ViewMoreCount = this.ViewMoreCount;
                userControl.ViewMore = this.ViewMore;
                userControl.FeedsCount = InitialFeedsCount;
                userControl.DataBind();
            }

        }
    }
}
